package com.ylfstu.Homework;

import java.util.ArrayList;
import java.util.Iterator;

@SuppressWarnings({"all"})
public class Homework02 {
    public static void main(String[] args) {
        ArrayList arrayList = new ArrayList();
        arrayList.add(new Car("宝马", 400000));
        arrayList.add(new Car("宾利", 5000000));
        arrayList.add(new Car("奥迪", 600000));
        //remove
//        arrayList.remove(1);
        //contains
        System.out.println(arrayList.contains(new Car("宝马", 400000)));
        //size
        System.out.println(arrayList.size());
        //isEmpty
        System.out.println(arrayList.isEmpty());
        //clear
//        arrayList.clear();
        //addAll
        ArrayList arrayList2 = new ArrayList();
        arrayList2.add(new Car("起亚", 200000));
        arrayList2.add(new Car("吉瑞", 130000));
        arrayList.addAll(arrayList2);
        //containsAll
        System.out.println(arrayList.containsAll(arrayList2));
        //removeAll
        System.out.println(arrayList.removeAll(arrayList2));

        System.out.println("-----增强for-----");
        for (Object o : arrayList) {
            System.out.println(o);
        }
        System.out.println("-----迭代器-----");
        Iterator iterator = arrayList.iterator();
        while (iterator.hasNext()) {
            Object next = iterator.next();
            System.out.println(next);
        }
    }
}
class Car{
    private String name;
    private double price;

    @Override
    public String toString() {
        return "Car{" +
                "name='" + name + '\'' +
                ", price=" + price +
                '}';
    }

    public Car(String name, double price) {
        this.name = name;
        this.price = price;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public double getPrice() {
        return price;
    }

    public void setPrice(double price) {
        this.price = price;
    }
}